<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String path = request.getContextPath();//获得项目的根目录，上下文路径
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<title>addSort.jsp</title>
<link rel="stylesheet" href="css/public.css" />
<link rel="stylesheet" href="css/style.css" />
<script src="js/jquery.js"></script>
<!-- $.ajaxSettings.async=false;//设置ajax同步 -->
<script type="text/javascript">

	//1、ajax验证作者
	function testAuthor(t) {
		var v = t.val();
		var sp = t.next();
		var div = t.parent();
		sp.empty();
		if (v == "") {
			sp.html("主人,地址不能为空哦！");
			div.removeClass("ok").addClass("error");
			return false;
		} else {
			sp.html("亲,地址正确哦!");
			div.removeClass("error").addClass("ok");
			return true;
		}
	}
	$(function() {
		$("#author").blur(function() {
			testAuthor($(this));
		});
	});

	//2、ajax验证标题
	function testTitle(t) {
		var v = t.val();
		var sp = t.next();
		var div = t.parent();
		sp.empty();
		if (v == "") {
			sp.html("主人,标题不能为空哦！");
			div.removeClass("ok").addClass("error");
			return false;
		} else {
			sp.html("亲,标题正确哦!");
			div.removeClass("error").addClass("ok");
			return true;
		}
	}
	$(function() {
		$("#title").blur(function() {
			testTitle($(this));
		});
	});

	//3、表单验证：addForm
	$(function() {
		$("#addForm").submit(
				function() {
					var flag = testAuthor($("#author"))
							& testTitle($("#title"));
					flag = flag == 0 ? false : true;
					alert(flag);
					return flag;
				});
	});

</script>
</head>
<body>
		<div class="right">
			<div class="providerAdd">
				<form action="st/toUserAdd" method="post" enctype="multipart/form-data" id="addForm">
					<div>
						<label for="sortId">发布版区：</label> <select name="sortId" id="sortId" style="width: 272px;">
							<option value="3">数据库</option>
							<option value="2">.net技术</option>
							<option value="1">java技术</option>
						</select> <span></span>
					</div>
					<div class="">
						<label for="author">作者：</label>
						<input type="text" name="author" id="author" />
						<span>*该选项请务必填写</span>
					</div>
					<div>
						<label for="title">标题：</label>
						<input type="text" name="title" id="title" />
						<span>*该选项请务必填写</span>
					</div>
					<div>
						<label for="detail">详细内容：</label>
						<input type="text" name="detail" id="detail" />
						<span></span>
					</div>
					<div class="providerAddBtn">
						<input type="submit" style="padding: 0px;" />
						<input type="reset" style="padding: 0px; width: 100px; font-size: 14px;" />
					</div>
				</form>
			</div>
		</div>
</body>
</html>